package com.mq.config4_topic;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TopicModelConfig {
    /**
     * 1. 添加一个交换机  topic.exchange
     * 2. 添加两个队列 topic.queue1、topic.queue2
     * 3. 绑定队列和交换机
     *      topic.queue1  topic.exchange  city.#
     *      topic.queue2  topic.exchange  gz.*
     */
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("topic.exchange");
    }
    @Bean
    public Queue topicQueue1() {
        return new Queue("topic.queue1");
    }
    @Bean
    public Queue topicQueue2() {
        return new Queue("topic.queue2");
    }

    @Bean
    public Binding topicBinding1(
            @Qualifier("topicQueue1") Queue topicQueue1, TopicExchange topicExchange) {
        return BindingBuilder.bind(topicQueue1).to(topicExchange).with("city.#");
    }

    @Bean
    public Binding topicBinding2(
            @Qualifier("topicQueue2") Queue topicQueue2, TopicExchange topicExchange) {
        return BindingBuilder.bind(topicQueue2).to(topicExchange).with("gz.*");
    }
}
